<template>
	<div class="content" @click='next'>
		<!-- 刷身份证-刷脸核身 -->
	</div>
</template>

<script>
import dayjs from 'dayjs';
import { Toast } from 'vant';
import {
  mapState,
  mapMutations,
  mapActions, mapGetters
} from 'vuex'

export default {
	data() {
		return {

		}
	},
	computed: {
		...mapState(['userInfo']),
    ...mapGetters(['isWenzhouAddress'])
	},
	mounted() {
    if(this.userInfo.verifyType=='face'){
      XhAggregation.getUserInfoByFace({
        success: (res) => {
          this.setUserInfo({
            ...res.data,
            encryptName: res.data.name,
            encryptIdCard: res.data.idCard,
            result: 'success',
          })
          this.next()
        },
        fail: (err) => {
          console.log('faceVerifyerr', err)
          this.failReturn()
        }
      })
    }else {
      XhAggregation.getUserInfoByIdcard({
        success: (res) => {
          console.log('res:getUserInfoByIdcard', res);
          this.setUserInfo({
            ...res,
            encryptName: res.name,
            encryptIdCard: res.idCard,
          })
          let toast = Toast.loading({
            message: '加载中...',
          });
          XhAggregation.faceVerify({
            data: {
              // "name": '余德明',
              // "idCard": '330327199708051596'
              "name": res.name,
              "idCard": res.idCard
            },
            success: (res) => {
              toast.clear()
              console.log(222, res);
              this.setUserInfo({
                result: 'success',
              })
              this.next()
            },
            fail: async (err) => {
              toast.clear()
              console.log('faceVerifyerr', err)
              // this.failReturn()
              // this.next()
              this.getUserInfoByFace()
            }
          })
        },
        fail: (err) => {
          console.log('getUserInfoByIdcarderr', err)
          this.failReturn()
        }
      })
    }
	},
	methods: {
		...mapMutations(['setUserInfo']),
		next() {
      // this.setUserInfo({
      //   headerPic: '',
      // })
			this.$router.push({
				path: 'confirm'
			})
		},
		failReturn() {
      // this.clearUserInfo()
			this.$router.push({
				path: '/index'
			})
		},
		getUserInfoByFace() {
      let toast = Toast.loading({
        message: '加载中...',
      });
			XhAggregation.getUserInfoByFace({
				success: (res) => {
          toast.clear()
					console.log(3333, res);
					if (res.data.idCard == this.userInfo.encryptIdCard) {
						this.next()
					} else {
						const dateTime = dayjs().format('YYYY-MM-DD HH:mm:ss')
						this.setUserInfo({
							faceIdCard: res.data.idCard,
							faceName: res.data.name,
							facePhone: res.data.mobile,
							result: 'fail',
							dateTime: dateTime,
						})
						this.$router.push({
							path: '/record/result'
						})
            // this.clearUserInfo()
						// this.next()
					}

				},
				fail: (err) => {
          toast.clear()
					console.log('faceVerifyerr', err)
					this.failReturn()
				}
			})
		}
	}
};
</script>
<style lang="less" scoped>
.content {
	
}
</style>